//
// Created by 67678 on 2023/3/16.
//

#ifndef WEBSERVER_CONCURRENTMAP_H
#define WEBSERVER_CONCURRENTMAP_H

#include <unordered_map>
#include <mutex>

using namespace std;

template<typename K, typename V>
class ConcurrentMap {
public:
    V &operator[](const K &k) {
        lock_guard lg(mx_);
        return mp_[k];
    }

    int erase(const K &k) {
        lock_guard lg(mx_);
        return mp_.erase(k);
    }

private:
    unordered_map<K, V> mp_;
    mutex mx_;
};

#endif //WEBSERVER_CONCURRENTMAP_H
